package handler

import (
	"minitool/backend/repository"
	"net/http"
	"strconv"

	"minitool/backend/service"

	"github.com/gin-gonic/gin"
)

func CreateWallpaper(ctx *gin.Context) {
	vipTypeStr := ctx.PostForm("vip_type")
	vipType, err := strconv.ParseInt(vipTypeStr, 10, 64)
	if err != nil {
		ctx.JSON(http.StatusBadRequest, gin.H{"result": err.Error()})
		return
	}

	hotStr := ctx.PostForm("hot")
	hot, err := strconv.ParseInt(hotStr, 10, 64)
	if err != nil {
		ctx.JSON(http.StatusBadRequest, gin.H{"result": err.Error()})
		return
	}

	authorUIDStr := ctx.PostForm("author_uid")
	authorUID, err := strconv.ParseInt(authorUIDStr, 10, 64)
	if err != nil {
		ctx.JSON(http.StatusBadRequest, gin.H{"result": err.Error()})
		return
	}

	wpTypeStr := ctx.PostForm("wp_type")
	wpType, err := strconv.ParseInt(wpTypeStr, 10, 64)
	if err != nil {
		ctx.JSON(http.StatusBadRequest, gin.H{"result": err.Error()})
		return
	}

	assetIDStr := ctx.PostForm("asset_id")
	assetID, err := strconv.ParseInt(assetIDStr, 10, 64)
	if err != nil {
		ctx.JSON(http.StatusBadRequest, gin.H{"result": err.Error()})
		return
	}

	meta := repository.WallpaperMeta{
		Name:         ctx.PostForm("name"),
		PreviewURL:   ctx.PostForm("preview_url"),
		VIPType:      vipType,
		Hot:          hot,
		AuthorUID:    authorUID,
		WpType:       wpType,
		WpURL:        ctx.PostForm("wp_url"),
		PreviewVideo: ctx.PostForm("preview_video"),
		OriginVideo:  ctx.PostForm("origin_video"),
		AssetID:      assetID,
		ExtraParam:   ctx.PostForm("extra_param"),
	}

	err = service.CreateWallpaper(ctx, &meta)
	if err != nil {
		ctx.JSON(http.StatusInternalServerError, err)
		return
	}

	ctx.JSON(http.StatusOK, gin.H{"result": "ok"})
}

func ListWallpaper(ctx *gin.Context) {
	ctx.JSON(http.StatusOK, gin.H{"result": "ok"})
}

func GetDetail(ctx *gin.Context) {
	ctx.JSON(http.StatusOK, gin.H{"result": "ok"})
}

func SearchWallpaper(ctx *gin.Context) {
	ctx.JSON(http.StatusOK, gin.H{"result": "ok"})
}

func GetDownloadURL(ctx *gin.Context) {
	ctx.JSON(http.StatusOK, gin.H{"result": "ok"})
}

func UpdateWallpaper(ctx *gin.Context) {
	ctx.JSON(http.StatusOK, gin.H{"result": "ok"})
}

func AdminUpdateWallpaper(ctx *gin.Context) {
	ctx.JSON(http.StatusOK, gin.H{"result": "ok"})
}
